package com.ceilcell.wx.atservice;

import com.ceilcell.wx.atservice.model.AccessToken;
import com.ceilcell.wx.atservice.service.AccessTokenService;
import com.ceilcell.wx.atservice.service.WeiXinServerIPService;
import com.ceilcell.wx.atservice.util.ConstantUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.net.ssl.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URL;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/4/18.
 */
@Component
public class Runner implements CommandLineRunner {

    @Autowired
    private AccessTokenService accessTokenService;

    @Autowired
    private WeiXinServerIPService weiXinServerIPService;

    public Runner(){
    }

    @Override
    public void run(String... args) throws Exception{

        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();

        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        service.scheduleAtFixedRate(new ScheduledGetAccessToken.ScheduledPositionSenderBuilder()
                        .accessTokenService(accessTokenService).weixinServerIPService(weiXinServerIPService).build()
                , ConstantUtil.SCHEDULE_GET_INIT, ConstantUtil.SCHEDULE_GET, TimeUnit.MILLISECONDS);


    }
}
